#import "Location.h"

/**
 * Contains generic location specific information
 * such as the name and GPSLocation
 * 
 * @author      Justin Hollander
 * @version     0.7.0     
 * @since       0.1.0
 * @see         PersistentDataType
 */
@implementation Location

@synthesize name;
@synthesize loc;

/**
 * Initialize the location with given information.
 *
 * @param nm        the name of the location
 * @param location  location of the location
 * @return          the initialized location with details
 */
-(id) initWithDetails:(NSString*)nm point:(GPSLocation*)location{
	if (self = [super init]) {
		self.name = nm;
		self.loc = location;
	}
	
	return self;
}

/**
 * Initializes the location from archive.
 *
 * @param decoder  the NSCoder used for decoding
 * @return         the location decoded from archive
 */
-(id)   initWithCoder:(NSCoder*)decoder{
	if ((self = [super init]) && ([decoder allowsKeyedCoding]))  {		
		self.name = [decoder decodeObjectForKey:@"LocationName"];
		self.loc = [decoder decodeObjectForKey:@"LocationGPSLocation"];

	}
	
	return self;
}

/**
 * Encodes the location for archiving options.
 *
 * @param encoder  the NSCoder used for encoding
 */
-(void) encodeWithCoder:(NSCoder*)encoder{
	if ([encoder allowsKeyedCoding]) {
		[encoder encodeObject:self.name forKey:@"LocationName"];
		[encoder encodeObject:self.loc forKey:@"LocationGPSLocation"];
	}
}

/**
 * Compute a unique key for the location.
 *
 * @return  the unique key
 */
-(NSString*) getKey
{
	return [NSString stringWithFormat:@"%@ %@ ", self.name, [self.loc getKey]];
}

/*
 * Deallocate the Location.
 */
-(void) dealloc{
	[name release];
	[loc release];
	[super dealloc];
}
@end
